---@diagnostic disable: lowercase-global, undefined-global, trailing-space

---@class api_drowning # 溺水系统 API
local dst_lan = {}

---为角色添加drowning组件并配置
---@param params data_drowning[] # drowning配置数据表
---@private
function dst_lan:AddToCharacters(params)
    for _, param in pairs(params) do
        AddPrefabPostInit(param.prefab, function(inst)
            if not TheWorld.ismastersim then
                return inst
            end
            
            -- 添加溺水组件
            if not inst.components.mod_pono_drowning then
                inst:AddComponent("mod_pono_drowning")
                
                -- 设置溺水惩罚参数
                if param.health_penalty then
                    inst.components.mod_pono_drowning:SetHealthPenalty(param.health_penalty)
                end
                
                if param.hunger_penalty then
                    inst.components.mod_pono_drowning:SetHungerPenalty(param.hunger_penalty)
                end
                
                if param.sanity_penalty then
                    inst.components.mod_pono_drowning:SetSanityPenalty(param.sanity_penalty)
                end
                
                if param.min_value then
                    inst.components.mod_pono_drowning:SetMinValue(param.min_value)
                end
                
                if param.moisture_gain then
                    inst.components.mod_pono_drowning:SetMoistureGain(param.moisture_gain)
                end
                
                if param.item_drop_fraction then
                    inst.components.mod_pono_drowning:SetItemDropFraction(param.item_drop_fraction)
                end
                
                print("[api_drowning] Drowning component added to", param.prefab)
            end
        end)
    end
end

---主函数
---@param params data_drowning[] # drowning配置数据表
function dst_lan:main(params)
    if params then
        self:AddToCharacters(params)
    end
end

return dst_lan
